import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
export type ExamRecordDocument = ExamRecord & Document;

// src/schemas/exam-records/exam-record.schema.ts
@Schema({ timestamps: true })
export class ExamRecord extends Document {
  @Prop({ type: Types.ObjectId, ref: 'User', required: true })
  userId: Types.ObjectId;

  @Prop({ type: Types.ObjectId, ref: 'Exam', required: true })
  examId: Types.ObjectId;

  @Prop({ default: '进行中', enum: ['进行中', '已完成', '异常终止'] })
  status: string;

  @Prop([{
    sectionId: Types.ObjectId,
    startTime: Date,
    endTime: Date,
    answers: [{
      questionId: Types.ObjectId,
      selectedOption: Number,
      isCorrect: Boolean
    }]
  }])
  sections: Record<string, any>[];

  @Prop({ default: 0 })
  totalScore: number;
}
export const ExamRecordSchema = SchemaFactory.createForClass(ExamRecord);